package com.hpu.service;

import java.util.ArrayList;
import java.util.List;
import com.hpu.dao.MenuDao;
import com.hpu.dao.OrderDao;
import com.hpu.dao.UserDao;
import com.hpu.entity.Menu;
import com.hpu.entity.Order;
import com.hpu.entity.User;

public class HomeService {

	private MenuDao menuDao = new MenuDao();
	private OrderDao orderDao = new OrderDao();
	private UserDao userDao = new UserDao();
	
	public List<Order> findAllOrders(){
		List<Order> orderList = orderDao.findAllOrders();
		fengzhuang(orderList);
		return orderList;
	}
	public void fengzhuang(List<Order> orderList){
		for (Order order : orderList) {
			List<Menu> menuList = new  ArrayList<Menu>();
			String menu_id = order.getMenu_id();
			String[] menuid = menu_id.split("_");
			for (String string : menuid) {
				int id = Integer.parseInt(string);
				Menu menu = menuDao.findMenuById(id);
				menuList.add(menu);
				order.setMenuList(menuList);
			}
		}
	}
	public List<Order> findAllPassOrders(){
		List<Order> orderList = orderDao.findAllPassOrders();
		fengzhuang(orderList);
		return orderList;
	}
	
	
	
	public List<Menu> findAllMenus(){
		return menuDao.findAllMenus();
	}
	public List<User> findAllUsers(){
		return userDao.findAllUsers();
	}
	
}
